package me.ymfs.springboot.guice.controller;

import com.google.common.collect.ImmutableList;
import me.ymfs.springboot.guice.aop.Logged;
import me.ymfs.springboot.guice.entity.User;
import me.ymfs.springboot.guice.service.user.UserService;
import me.ymfs.springboot.guice.util.RandomStringUtils;
import me.ymfs.springboot.guice.vo.RespVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(value = "/{id}")
    @Logged(desc = "查询用户")
    public RespVO getUserById(@PathVariable Long id) {
        return RespVO.success("查询成功", userService.selectByPrimaryKey(id));
    }

    @GetMapping(value = "/bat")
    @Logged(desc = "查询用户")
    public RespVO batQueryUsers() {
        String jsid = RandomStringUtils.uuid32();
        ImmutableList.Builder<User> builder = ImmutableList.builder();
        for (int i = 0; i < 20; i++) {
            builder.add(userService.batQueryUsers(jsid));
        }
        return RespVO.success("查询成功", builder.build());
    }

}
